package com.sx.form.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.sx.form.dao.ITitleDao;
import com.sx.form.entity.TitleEntity;


/**
 * @author Administrator
 * TitleDao 接口实现类
 */
public class TitleDao extends SqlMapClientDaoSupport implements ITitleDao {
	

	/* (non-Javadoc)
	 * @see com.demo.dao.ITitleDao#findTitlesByPaging(com.demo.entity.TitleEntity)
	 */
	public List<TitleEntity> findTitlesByPaging(TitleEntity title)
			throws Exception {
		// TODO Auto-generated method stub
		List<TitleEntity> list = new ArrayList<TitleEntity>();
		try {
			list = super.getSqlMapClientTemplate().queryForList("Title.queryAllByPaging",title);
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception(e);
			// TODO: handle exception
		} 
		return list;
	}

	/* (non-Javadoc)
	 * @see com.demo.dao.ITitleDao#addTitle(com.demo.entity.TitleEntity)
	 */
	public Integer addTitle(TitleEntity title) throws Exception {
		Integer id = new Integer(0);
		try {
			id = (Integer)super.getSqlMapClientTemplate().insert("Title.addTitle", title);
		} catch (Exception e) {
			// TODO: handle exception
			throw new Exception(e);
		}
		return id;
	}

	/* (non-Javadoc)
	 * @see com.demo.dao.ITitleDao#deleteTitle(com.demo.entity.TitleEntity)
	 */
	public boolean deleteTitle(TitleEntity title) throws Exception {
		// TODO Auto-generated method stub
		boolean flag = false;
		try {
			int count = getSqlMapClientTemplate().delete("Title.deleteTitle", title);
			if(count>0){
				flag = true;
			}
		} catch (Exception e) {
			// TODO: handle exception
			throw new Exception(e);
		}
		return flag;
	}

	/* (non-Javadoc)
	 * @see com.demo.dao.ITitleDao#findTitles(com.demo.entity.TitleEntity)
	 */
	public List<TitleEntity> findTitles(TitleEntity title) throws Exception {
		// TODO Auto-generated method stub
		List<TitleEntity> list = new ArrayList<TitleEntity>();
		try {
			list = super.getSqlMapClientTemplate().queryForList("Title.queryAll", title);
		} catch (Exception e) {
			// TODO: handle exception
			throw new Exception(e);
		}
		return list;
	}

	/* (non-Javadoc)
	 * @see com.demo.dao.ITitleDao#updateTitle(com.demo.entity.TitleEntity)
	 */
	public boolean updateTitle(TitleEntity title) throws Exception {
		// TODO Auto-generated method stub
		boolean flag = false;
		try {
			int count = getSqlMapClientTemplate().update("Title.updateTitle", title);
			if(count>0){
				flag = true;
			}
		} catch (Exception e) {
			// TODO: handle exception
			throw new Exception(e);
		}
		return flag;
	}

}
